<pre>

<?php
$start = microtime(true);



require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Lead_Db');

$dbArr = array(
'host'     => '127.0.0.1',
'username' => 'pekkis',
'password' => 'savethemanatee',
'dbname'   => 'edox'
);

$driver = 'PDO_PGSQL';

if(isset($_GET['mysql'])) {

	$dbArr = array(
	'host' => '127.0.0.1',
	'username' => 'root',
	'password' => 'savethemanatee',
	'dbname' => 'edo'
	);
	
	$driver = 'PDO_MYSQL';
    
    
}




$db = Lead_Db::factory($driver, $dbArr);
Zend_Loader::loadClass('Lead_EDO');


$backend = array(
    'backend' => 'Memcached',
    'backendOptions' => array('servers' => array('host' => 'localhost','port' => 11211, 'persistent' => true)),
);

$backend = false;

// $backend = array('backend' => 'File', 'backendOptions' => array());

// initialize EDO handler.
$handler = Lead_EDO::factory($db, $backend);

// add a new path for EDO classes.
$handler->addPath('/wwwroot/LEAD/library/Lead/EDO/Model');

print "<hr />";
print microtime(true) - $start;
print "<hr />";



$tests = array();

try {
    
    $allTests = $handler->getFinder('Test')->findAll();
    
    foreach($allTests as $key => $value) {
        
        print $value->id . ";";
        
        
        $tests[$key] = $value;
    }
    
    
    
} catch(Exception $e) {
    
    print $e->getMessage();
    
    print "<hr />poopinglooper halted, fetch failed<hr />";
}

print "<hr />";

print "sizeof allTests:" . sizeof($allTests);

print "<hr />";


print "<hr />";
print microtime(true) - $start;
print "<hr />";


/*
$finder = $handler->getFinder('Test');
$tests = $finder->findAll(array(), false);
foreach($tests as $test) {
    $test->delete();
}
*/

// $db->query("DELETE FROM edo");

print "<hr />";
print microtime(true) - $start;
print "<hr />";

if(!$test = $handler->getFinder('Test')->findFirst()) {
    $test = $handler->get('Test');
}



foreach($test->getFieldObjects() as $fieldObj) {
    
    if($fieldObj instanceof Lead_EDO_Datatype_Field_Value)
        print $fieldObj->getName() . ': ' . $fieldObj->getValue() . "<br />"; 
    
}



$test->test_bigint = 543987443;
$test->test_boolean = false;
$test->test_char = 'chara';
$test->test_date = '2006-01-01';
$test->test_datetime = '2006-01-01 23:22:22';
$test->test_decimal = 1.564;
$test->test_double = 1.564327237;
$test->test_integer = -546;
$test->test_single = 45.564327237;
$test->test_smallint = 5447;

$test->test_string = 'boxerit';
$test->test_text = 'stringit';



if($test->isFetched())
    $success = $test->save();
else 
    $success = $test->insert();

var_dump($success);



$test->delete();


/*

$test = $handler->get('Test');

$test->test_integer = 5;
$test->test_string = 'varchar';
$test->test_smallint = 6;
$test->test_bigint = 66;
$test->test_char = 'fifi';
$test->test_datetime = '2008-05-31';
$test->test_text = 'Lorem Ipsum Dolor Sit Amet';
$test->test_single = 0.535;
$test->test_double = 0.587374;
$test->test_boolean = true;
$test->test_decimal = 1.53;


$test->insert();



$container = $handler->get('Container');
$container->container_name = 'Test Container';
$container->insert(true);

$suite = $handler->get('Suite');
$suite->suite_name = 'Test Suite';
$suite->container_id = $container->id;
$suite->insert(true);

*/

/*

$suite = $handler->fetch(64);

$relation = $suite->container();


$container = $relation->getValue();

$suites = $container->suites;

$test = $handler->fetch(62);


var_dump($test->suites);

*/







/*
Zend_Loader::loadClass('Lead_Sql_Query');

$query = new Lead_Sql_Query(false);

$query->addOrderer('edo.id ASC');

$query->addWhereGroup('AND');

$whereGroup = $query->getCurrentWhereGroup();

$query->addField('*', true);
$query->addTable('edo');


$query->addJoin('test', 'left', 'edo.id = test.id', false);


$sql = $query->getSQL();

print $sql;

print "<hr />";

$rows = $db->fetchAll($sql);

print_r($rows);


print_r($container);
print_r($suite);
print_r($test);


$container->container_name = 'Test container';
$container_id = $container->insert(true);

$test->test_integer = 5;
$test->test_string = 'varchar';
$test->test_smallint = 6;
$test->test_bigint = 66;
$test->test_char = 'fifi';
$test->test_datetime = '2008-05-31';
$test->test_text = 'Lorem Ipsum Dolor Sit Amet';
$test->test_single = 0.535;
$test->test_double = 0.587374;
$test->test_boolean = true;
$test->test_decimal = 1.53;
$test->container_id = $container_id;

$test->insert();

$test->insert(true);



$suite->suite_name = 'Test Suite';
$suite->container_id = $container_id;
$suite->insert(true);
*/

print "<pre>";

foreach($allTests as $testObj) {
    $testObj->delete();
}

print "</pre>";

try {
    $test = $handler->fetch(102);    
} catch(Exception $e) {
    print "EDO with 102 id not found.... :( :) <br />";
}



// $GLOBALS['puuppa']->commit();




print "<hr />";

print microtime(true) - $start;




?>
</pre>